<template>
  <div class="td-patient-me-address">
    <mt-header fixed title="地址管理">
      <router-link to="tdSetting" slot="left">
        <mt-button icon="back"></mt-button>
      </router-link>
    </mt-header>

    <mt-cell
      v-for="(item,index) in addressList"
      :key="index"
      :title="`${item.ReceiverName}${item.IsDefault?' -> 默认地址':''}`"
      :label="`${item.ProviceName}${item.CityName}${item.AreaName}${item.StreetDetail}`"
      :class="{'default':item.IsDefault}"
    >
      <span class="icon font_family icon-td-xinxi" @click="btnModify(item);"></span>
    </mt-cell>
    <mt-cell title="新增地址" is-link @click.native="$router.push({name:'tdAddressModify'})">
      <span slot="icon" class="icon font_family icon-td-tianjia"></span>
    </mt-cell>
  </div>
</template>

<script>
import UserAddressService from "../../../../_services/userAddress.service";
export default {
  name: "TianDingPatientMeAddressComponent",
  data() {
    return {
      user: {},
      addressList: []
    };
  },
  mounted() {
    this.user = this.utils$.dataFormat(
      JSON.parse(this.local$.getItem("tdUser"))
    );
    this.getUserAddressList();
  },
  methods: {
    getUserAddressList() {
      this.addressList = [];
      let args = {
        UserID: this.user.UserID,
        PageIndex: 1,
        PageSize: 100,
        Orderby: "AddressID",
        IsDesc: true
      };
      UserAddressService.getUserAddressList(args).then(response => {
        if (response && response.Data && response.Data.Items.length > 0) {
          this.addressList = response.Data.Items;
        }
      });
    },
    btnModify(item) {
      this.$router.push({ name: "tdAddressModify", params: item });
    }
  }
};
</script>

